package com.peng.leetcode.swordoffer;

import java.util.LinkedList;

/**
 * CQueue
 * 剑指 Offer 09. 用两个栈实现队列
 * https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
 *
 * @author: lupeng6
 * @create: 2023/3/10 11:34
 */
public class Sword9CQueue {

    LinkedList<Integer> inStack;
    LinkedList<Integer> outStack;


    public Sword9CQueue() {
        this.inStack = new LinkedList<>();
        this.outStack = new LinkedList<>();
    }

    public void appendTail(int value) {
        inStack.offerLast(value);
    }

    public int deleteHead() {
        if (!outStack.isEmpty()) {
            return outStack.pollLast();
        }
        if (inStack.isEmpty()) {
            return -1;
        } else {
            while (!inStack.isEmpty()) {
                outStack.offerLast(inStack.pollLast());
            }
        }
        return this.outStack.pollLast();
    }
}
